import type { App } from "vue";
import { useUserInfoStore } from "@/stores/userInfo";

const registerPermissionDirective = (app: App) => {
  app.directive("permission", (el, binding) => {
    /*
      el 绑定指令的DOM元素
      binding 是一个对象，包含指令内容
        {
          expression: 'count',
          value: 0
        }
        v-permission="'btn.User.add'"
    */
    const userInfoStore = useUserInfoStore();
    if (!userInfoStore.buttons.includes(binding.value)) {
      // 删除DOM元素
      el.remove();
    }
  });
};

export default registerPermissionDirective;
